<template>
	<view>
		        <u-datetime-picker
		          :show="showCalendar"
		          v-model="currentValue"
		          mode="year-month"
				  closeOnClickOverlay
				  @close="showCalendar = false"
				  @cancel="showCalendar = false"
				  @confirm="confirmSearch"
		        ></u-datetime-picker>
		<view class="income">
		 <z-paging ref="paging" v-model="dataList" @query="queryList">
		   <template #top>
			   <view class="income-head">
			   	<view class="income-head-left" @click="showCalendar= true">
			   		<text>{{ machineDto.month }}</text>
			   		<view style="margin-left: 12rpx;">
			   			<u-icon name="arrow-down"  size="18"></u-icon>
			   		</view>
			   	</view>
			   	<view  class="income-head-right">
			   		<text>全部</text>
			   		<view style="margin-left: 12rpx;">
			   			<u-icon name="arrow-down"  size="18"></u-icon>
			   		</view>
			   	</view>
			   </view>
		   </template>
	<!-- 		<view class="income-none">
				<image src="https://kx.taipingkeji.com/upload/1/common/images/20240229/20240229112535170922033573181.png" mode="aspectFill"></image>
			</view>
			<view class="income-none-title">
				暂无收益明细
			</view> -->
			<view class="income-centent">
				<view class="income-centent-card" v-for="(item, index) of dataList" :key="index">
					<view class="income-centent-card-title">
											<view>设备ID: {{ item.device_id }}</view>
					</view>
					<view style="margin: 0 24rpx;">
						<u-line></u-line>
					</view>
					<view class="income-centent-card-main">
						<view class="income-centent-card-main-left">
							<view style="line-height: 1.5;">开启时间: {{ item.start_time }}</view>
							<view style="line-height: 1.5;">结束时间: {{ item.end_time }}</view>
						</view>
					</view>
				</view>
			</view>
		</z-paging>
	   </view>
	</view>
</template>

<script>
	import request from "@/api/request.js"
    import dayJS from 'dayjs'
	export default {
		data() {
			return {
				showCalendar: false,
				dataList:[],
				currentValue: dayJS().format('YYYY-MM'),
				machineDto: {
				  token: '' ,
				  month: dayJS().format('YYYY-MM-DD'),
				  page: 1,
				  page_size: 10
				},
			}
		},
		onLoad() {
		  this.machineDto.token = uni.getStorageSync('token')
		},
		computed: {},
		methods: {
			confirmSearch(val){
				this.machineDto.month = dayJS(val.value).format('YYYY-MM')
				this.$refs.paging.reload()
				this.showCalendar = false
			},
			queryList(page, page_size){
				uni.showLoading({
					title: '加载中...'
				})
				const that = this
				this.machineDto.page = page
				this.machineDto.page_size = page_size
				request({
					url: "/kx/Personal/powerList",
					method: "POST",
					data:this.machineDto,
					successCb(res){
						uni.hideLoading()
						const { data: tempData } = res.data
						if(tempData){
							res.data.data.forEach(item => {
								item.start_time = dayJS(item.start_time * 1000).format('YYYY-MM-DD HH:mm:ss')
								item.end_time = dayJS(item.end_time * 1000).format('YYYY-MM-DD HH:mm:ss')
							})
						}
						that.$refs.paging.complete(res.data.data);
					},
					failCb(res){
						uni.hideLoading()
						that.$refs.paging.complete(false);
					}
				})
			}
		}
	}
</script>

<style lang="scss">
.income{
	display: flex;
	flex-direction: column;
	align-items: center;
	font-size: 36rpx;
	width: 100%;
	min-height: 100vh;
	background-color: #f6f6f6; 
	&-none {
	  &-title {
		font-size: 28rpx;
		color: #606060;
	  }
	}
	&-head {
	 width: 100%;
	 @include layout(space-around,center);
	 color: #606060;
	 font-size: 24rpx;
	 padding: 24rpx;
	 
	 &-left {
		 @include layout(start,center);
	 }
	 &-right {
	  @include layout(start,center);	 
	 }
	}
	&-centent {
	 margin: 24rpx 0;
	 &-card {
		width: 680rpx;
		height: 168rpx;
		background: $uni-bg-color;
		border-radius: 20rpx;
		margin: 12rpx auto;
		&-title {
			padding: 18rpx;
			font-size: 30rpx;
		}
		&-main {
		 @include layout(space-between, center);
		 padding:  18rpx;
		 &-left {
		   font-size: 24rpx;
		   color: #6D6D6D;
		 }
		 &-right {
		  font-size: 28rpx;	 
		 }
		
		}
	 }	
	}
}
</style>
